package com.poi.proj;

/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */



import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;

import java.io.FileOutputStream;
import java.io.IOException;

/**
* Illustrates how to create cell values.
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class CreateCells {
 public static void main(String[] args) throws IOException {
     HSSFWorkbook wb = new HSSFWorkbook();
     HSSFSheet sheet = wb.createSheet("new sheet");

     // Create a row and put some cells in it. Rows are 0 based.
     HSSFRow row = sheet.createRow(0);
     //row.setHeight((short)0x1000);
     // Create a cell and put a value in it.
     HSSFCell cell = row.createCell(0);
     cell.setCellValue(1);

     // Or do it on one line.
     row.createCell(1).setCellValue(1.2);
     HSSFCell c2 =  row.createCell(2);
     String cellValue = "在换取登机牌的时候，请务必告知航空公司工作人员，行李直挂最后要到达的目的地。每人可免费托运一件20公斤的行李，请务必上锁，以免物品丢失。水果刀请放在托运行李中，所有液体，包括：洗头水，沐浴液，饮料等都禁止随身带上机舱，必须跟随行李托运。最新《民航管理条例》手机电池或相机电池必须随身携带不得托运；打火机不得托运。贵重物品请随身携带。";
     c2.setCellValue(cellValue);
     System.out.println(cellValue.length() / 50);
     row.setHeight((short)(0x100 * (cellValue.length() / 13 + 1)));
     c2.setCellType(HSSFCell.CELL_TYPE_STRING);
     HSSFFont f2 = wb.createFont();
     HSSFCellStyle cs = wb.createCellStyle();
	 cs = wb.createCellStyle();
	 cs.setFont(f2);
	 cs.setWrapText(true);
     c2.setCellStyle(cs);
     sheet.setColumnWidth(2, (int) ((50 * 8) / ((double) 1 / 20)));
     row.createCell(3).setCellValue(true);

     
     // Write the output to a file
     FileOutputStream fileOut = new FileOutputStream("D:/workbook.xls");
     wb.write(fileOut);
     fileOut.close();
 }
}

